package org.csu.wuliu.controller;


import org.apache.ibatis.jdbc.Null;
import org.csu.wuliu.domain.Category;
import org.csu.wuliu.domain.Supplier;
import org.csu.wuliu.persistence.SupplierMapper;
import org.csu.wuliu.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/supplier/")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;


    /*返回类型
[
{
    "supplierId": "1",
    "supplierName": "供应商1",
    "address": "北京朝阳村",
    "telephone": "10086",
    "email": "10086@qq.com"
}
]
 */

    @ResponseBody
    @GetMapping("suppliers")
    public List<Supplier> getsuplList()  {

        List<Supplier> suppliers = supplierService.getSupplierList();
        if(suppliers== null){System.out.println("kong");}
        return suppliers;
    }

    @ResponseBody
    @DeleteMapping("suppliers")
    public String deletesupl(@RequestParam String supplierId)  {
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!"+supplierId);
        supplierService.deleteSupplier(supplierId);
        return "成功";
    }


    @PostMapping("suppliers")
    public String newsupl(Supplier supplier)  {
        System.out.println("7777777777777777777777777777777777"+supplier.getSupplierId());
        supplierService.insertSupplier(supplier);
        return "成功";
    }

    @PatchMapping("suppliers")
    public String updatesupl(Supplier supplier){
        supplierService.updateSupplier(supplier);
        System.out.println(supplier.getSupplierId());
        System.out.println(supplier.getSupplierName());
        return "成功";
    }

}
